package com.goodwill.androidtest.optional;

import android.os.Build;

import androidx.annotation.RequiresApi;

import java.util.ArrayList;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;

public class OptionalTest {
    public static void main(String[] args) {
        try {
            testOptional();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    private static void testOptional() throws Throwable {
//        Optional<String> stringOptional = new ArrayList<String>();
//        User user = new User("李小龙", 28);
        User user = null;
        String name = "guoxiaojun";
//        Optional.ofNullable(name)
//                .flatMap()
//                .isPresent(v-> Process v)
//                .map(n -> user.getName())
//                .orElseGet(() -> "")
//                .orElseThrow(() -> new NullPointerException("参数错误"));

        Stream<Integer> stream = Stream.of(1, 3, 4);
//        stream.iterator()
        stream.forEach(System.out::println);
    }
}
